'''
Created on May 7, 2011

@author: james
'''

class SingleShiftPerDayEvaluator(object):
    '''
    doctor cannot be assigned multiple shifts in same day
    '''

    def __init__(self, schedule, initCount, multiplier):
        self._schedule = schedule
        self._initCount = initCount
        self._multiplier = multiplier
        
    def evaluate(self, chromosome, debug = False):
        
        dayOfMonth = 0
        index = 0
        score = len(self._schedule)
        
        for shiftsInDay in self._schedule:
            dayOfMonth += 1
            counts = self._initCount.copy()
            
            for _ in range(shiftsInDay):
                doctor = chromosome[index]
                counts[doctor] += 1
                index += 1
                             
            for _, value in counts.items():
                if value > 1: 
                    if debug: print "Doctor duplication on day %02d, %i" % (dayOfMonth, index)  
                    score -= 1
        
        if debug: print "SingleShiftPerDayEvaluator score: %d" % score
        
        return score * self._multiplier  
    
    def evaluateConvergenceCriteria(self, chromosome, attempt):
        return self.evaluate(chromosome) == (len(self._schedule) * self._multiplier)
        
        
    